package info.openlvb.openface.client.handler;

import info.openlvb.openface.client.base.machine.ListMachinePanel;
import info.openlvb.openface.client.base.machine.MachineWindow;
import info.openlvb.openface.client.service.LdapService;
import info.openlvb.openface.client.service.LdapServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

public class ModifyMachineListener extends ButtonListenerAdapter {

	private MachineWindow machineWindow;
	//private ListMachinePanel listMachinePanel;
	private String uid;
	private final LdapServiceAsync ldapService = GWT.create(LdapService.class);
	
	public ModifyMachineListener(MachineWindow machineWindow,
			ListMachinePanel listMachinePanel, String uid) {
		this.machineWindow = machineWindow;
		//this.listMachinePanel = listMachinePanel;
		this.uid = uid;
	}

	public void onClick(Button button, EventObject e) {
		ldapService.modifyMachine(uid, machineWindow.getTxt_nom().getText(),
				machineWindow.getTxt_desc().getText(), new AsyncCallback<Void>() {
					public void onSuccess(Void result) {
						MessageBox.alert("l'ordinateur a été modifié");
						machineWindow.hide();
					}
					public void onFailure(Throwable caught) {
						MessageBox.alert("probleme de backend");
					}
				});
	}


}
